//
//  HXSelectedPersonViewController.m
//  KD
//
//  Created by ifly on 16/2/26.
//  Copyright © 2016年 ifly. All rights reserved.
//

//一些UITextField和UIPickerView的tag
#define AreaViewTag 10
#define CorpKindViewTag 11
#define GradeViewTag 12
#define CorpViewTag 13
#define PersonViewTag 14

#define AreaStr @"地区"
#define CorpKindStr @"企业类型"
#define GradeStr @"资质等级"
#define CorpStr @"企业"
#define PersonKindStr @"人员类型"

#define AlertFiveStr @"暂无资质等级"
#define AlertFourStr @"暂无企业"
#define AlertThreeStr @"暂无人员类型"
#define AlertTwoStr @"请先选择企业类型"
#define AlertOneStr @"请先选择其他筛选信息"

#import "HXSelectedPersonViewController.h"
#import "HXSelectedPersonResultView.h"
#import "HXBtnSelectedView.h"
#import "HXSelectedDataDictModel.h"

@interface HXSelectedPersonViewController ()<UIGestureRecognizerDelegate,UIPickerViewDataSource,UIPickerViewDelegate,UITextFieldDelegate,HXBtnSelectedViewDelegate,HXSelectedPersonResultViewDelegate>
@property(strong,nonatomic)UIView *maskView;
@property(nonatomic,strong) UITapGestureRecognizer *tapGestureRec;
@property(strong,nonatomic)HXSelectedPersonResultView *selectedPerson;//人员展示view
@property(nonatomic,strong) UIToolbar  *keyboardDoneButtonBar;
@property (weak, nonatomic) IBOutlet UIButton *siftBtn;
@property (weak, nonatomic) IBOutlet UITextField *siftTextField;
@property (weak, nonatomic) IBOutlet UIButton *okBtn;

@property (weak, nonatomic) IBOutlet UIView *areaSelectedView;
@property (weak, nonatomic) IBOutlet UIView *corpKindSelectedView;
@property (weak, nonatomic) IBOutlet UIView *gradeSelectedView;
@property (weak, nonatomic) IBOutlet UIView *corpSelectedView;
@property (weak, nonatomic) IBOutlet UIView *personKindSelectedView;

@property(nonatomic,strong) HXBtnSelectedView *areaBtnSelectedView;
@property(nonatomic,strong) HXBtnSelectedView *corpKindBtnSelectedView;
@property(nonatomic,strong) HXBtnSelectedView *gradeBtnSelectedView;
@property(nonatomic,strong) HXBtnSelectedView *corpBtnSelectedView;
@property(nonatomic,strong) HXBtnSelectedView *personKindBtnSelectedView;

@property (strong, nonatomic)  UITextField *areaTextField;//tag AreaViewTag
@property (strong, nonatomic)  UITextField *corpKindTextField;//tag CorpKindViewTag
@property (strong, nonatomic)  UITextField *gradeTextField;//tag GradeViewTag
@property (strong, nonatomic)  UITextField *corpTextField;//tag CorpViewTag
@property (strong, nonatomic)  UITextField *personKindTextField;//tag PersonViewTag

/**地区的pickerView*/
@property(nonatomic,strong) UIPickerView *areaPickerView;//tag AreaViewTag
/**企业类型的pickerView*/
@property(nonatomic,strong) UIPickerView *corpKindPickerView;//tag CorpKindViewTag
/**资质等级的pickerView*/
@property(nonatomic,strong) UIPickerView *gradePickerView;//tag GradeViewTag
/**资质等级的pickerView*/
@property(nonatomic,strong) UIPickerView *corpPickerView;//tag CorpViewTag
/**人员类型的pickerView*/
@property(nonatomic,strong) UIPickerView *personKindPickerView;//tag PersonViewTag


/**网络数据-地区*/
@property(nonatomic,strong) NSMutableArray<HXAreaKindListModel *> *areaArray;
/**网络数据-企业*/
@property(nonatomic,strong) NSMutableArray<HXCorpKindListModel *> *corpKindArray;
/**网络数据-资质等级*/
@property(nonatomic,strong) NSMutableArray<HXGradeKindListModel *> *gradeArray;
/**网络数据-资质等级*/
@property(nonatomic,strong) NSMutableArray<HXCorpListModel *> *corpArray;
/**网络数据-人员类型*/
@property(nonatomic,strong) NSMutableArray<HXPersonKindListModel *> *personKindArray;
/**网络数据-具体人员*/
@property(nonatomic,strong) NSArray<HXPersonSelectedListModel *> *personArray;
@end

@implementation HXSelectedPersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.maskView.alpha = 0.2;
    [self getAreaAndCorpKindData];//拉取地区和企业类型数据
    [self setUpBtnSelectedView];//添加可滑动选中的信息显示条
    [self setUpSelectedView];//设置按钮圆角
    self.automaticallyAdjustsScrollViewInsets = NO;
}

//拉取地区和企业类型数据
-(void)setUpBtnSelectedView{
    HXBtnSelectedView *areaBtnSelectedView = [HXBtnSelectedView initWithName:AreaStr];
    areaBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
    areaBtnSelectedView.delegate = self;
    [self.areaSelectedView addSubview:areaBtnSelectedView];
    self.areaBtnSelectedView = areaBtnSelectedView;
    
    
    HXBtnSelectedView *corpKindBtnSelectedView =  [HXBtnSelectedView initWithName:CorpKindStr];
    corpKindBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
    corpKindBtnSelectedView.delegate = self;
    [self.corpKindSelectedView addSubview:corpKindBtnSelectedView];
    self.corpKindBtnSelectedView = corpKindBtnSelectedView;
    
    
    
    HXBtnSelectedView *gradeBtnSelectedView =  [HXBtnSelectedView initWithName:GradeStr];
    gradeBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
    gradeBtnSelectedView.delegate = self;
    [self.gradeSelectedView addSubview:gradeBtnSelectedView];
    self.gradeBtnSelectedView = gradeBtnSelectedView;
    
    
    
    HXBtnSelectedView *corpBtnSelectedView =  [HXBtnSelectedView initWithName:CorpStr];
    corpBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
    corpBtnSelectedView.delegate = self;
    [self.corpSelectedView addSubview:corpBtnSelectedView];
    self.corpBtnSelectedView = corpBtnSelectedView;
    
    HXBtnSelectedView *personKindBtnSelectedView =  [HXBtnSelectedView initWithName:PersonKindStr];
    personKindBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
    personKindBtnSelectedView.delegate = self;
    [self.personKindSelectedView addSubview:personKindBtnSelectedView];
    self.personKindBtnSelectedView = personKindBtnSelectedView;
}
//添加可滑动选中的信息显示条
-(void)setUpSelectedView{
    self.siftBtn.layer.cornerRadius = 3;
    self.okBtn.layer.cornerRadius = 6;
    
    //self.areaSelectedView.layer.cornerRadius = 6;
    //self.areaSelectedView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //self.areaSelectedView.layer.borderWidth = 0.6;
    
    //self.corpKindSelectedView.layer.cornerRadius = 6;
    //self.corpKindSelectedView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //self.corpKindSelectedView.layer.borderWidth = 0.6;
    
    //self.corpSelectedView.layer.cornerRadius = 6;
    //.corpSelectedView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //self.corpSelectedView.layer.borderWidth = 0.6;
    
    //self.gradeSelectedView.layer.cornerRadius = 6;
    //self.gradeSelectedView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //self.gradeSelectedView.layer.borderWidth = 0.6;
    
    //self.personSelectedView.layer.cornerRadius = 6;
    //self.personSelectedView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //self.personSelectedView.layer.borderWidth = 0.6;
}

-(void)getAreaAndCorpKindData{
    //获取地区列表
    [NetworkAPI getAreaKindSuccess:^(HXAreaKindModel *result) {
        if ([result.code isEqualToString:@"200"]) {
            [self.areaArray addObjectsFromArray:result.resultlist];
//            
//            for (int i = 0; i<result.resultlist.count; i++) {
//                NSMutableArray *array = [[NSMutableArray alloc]initWithArray:result.resultlist[i]];
//                self.areaArray addObject:<#(nonnull HXAreaKindListModel *)#>
//            }
//            for (HXAreaKindListModel *model in self.areaArray) {
//                HXAreaKindAreasListModel *models = [[HXAreaKindAreasListModel alloc]init];
//                models.area = @"";
//                models.areacode = @"";
//                [model.areas insertObject:models atIndex:0];
//            }
            [self.areaPickerView reloadAllComponents];
        }else{
            [SVProgressHUD showErrorWithStatus:@"获取地区列表为空"];
        }
    } failure:^(NSError *err) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
    
    //获取企业类型列表
    [NetworkAPI getCorpKindSuccess:^(HXCorpKindModel *result) {
        if ([result.code isEqualToString:@"200"]) {
            [self.corpKindArray removeAllObjects];
            [self.corpKindArray addObjectsFromArray:result.resultlist];
            HXCorpKindListModel *model = [[HXCorpKindListModel alloc]init];
            model.typeName = @"";
            model.typeValue = @"";
            [self.corpKindArray insertObject:model atIndex:0];
            [self.corpKindPickerView reloadAllComponents];
        }else{
            [SVProgressHUD showErrorWithStatus:@"获取企业类型列表为空"];
        }
    } failure:^(NSError *err) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
}

-(void)getGradeAndPersonData{
    NSString *str = [self.corpKindBtnSelectedView allCode];
    [SVProgressHUD showWithStatus:@"正在获取人员类型和资质等级" ];
    [NetworkAPI getQualityKindWithCkind:str
          success:^(HXGradeKindModel *result) {
              [SVProgressHUD dismiss];
              if ([result.code isEqualToString:@"200"]) {
                  [self.gradeArray removeAllObjects];
                  [self.gradeArray addObjectsFromArray:result.resultlist];
                  HXGradeKindListModel *model = [[HXGradeKindListModel alloc]init];
                  model.typeName = @"";
                  model.typeValue = @"";
                  [self.gradeArray insertObject:model atIndex:0];
                  [self.gradePickerView reloadAllComponents];
              }else{
                  [self.gradeArray removeAllObjects];
                  HXGradeKindListModel *model = [[HXGradeKindListModel alloc]init];
                  model.typeName = @"暂无资质等级";
                  model.typeValue = @"";
                  [self.gradeArray insertObject:model atIndex:0];
                  [self.gradePickerView reloadAllComponents];
              }
          } failure:^(NSError *err) {
              [SVProgressHUD dismiss];
              [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
    
    [NetworkAPI getPersonKindWithCkind:str
          success:^(HXPersonKindModel *result) {
              [SVProgressHUD dismiss];
              if ([result.code isEqualToString:@"200"]) {
                  [self.personKindArray removeAllObjects];
                  [self.personKindArray addObjectsFromArray:result.resultlist];
                  HXPersonKindListModel *model = [[HXPersonKindListModel alloc]init];
                  model.typeName = @"";
                  model.typeValue = @"";
                  [self.personKindArray insertObject:model atIndex:0];
                  [self.personKindPickerView reloadAllComponents];
              }else{
                  [self.personKindArray removeAllObjects];
                  HXPersonKindListModel *model = [[HXPersonKindListModel alloc]init];
                  model.typeName = @"暂无人员类型";
                  model.typeValue = @"";
                  [self.personKindArray insertObject:model atIndex:0];
                  [self.personKindPickerView reloadAllComponents];
              }
          } failure:^(NSError *err) {
              [SVProgressHUD dismiss];
              [SVProgressHUD showErrorWithStatus:@"网络错误"];
          }];
}

-(void)getCorpData{
    [SVProgressHUD showWithStatus:@"正在获取企业列表" ];
    [NetworkAPI getCorpWithAeraCode:[self.areaBtnSelectedView allCode]
    CorpKind:[self.corpBtnSelectedView allCode]
    CorpQuality:[self.gradeBtnSelectedView allCode]
    success:^(HXCorpModel *result) {
        [SVProgressHUD dismiss];
        if ([result.code isEqualToString:@"200"]) {
            [self.corpArray removeAllObjects];
            [self.corpArray addObjectsFromArray:result.corplist];
            HXCorpListModel *model = [[HXCorpListModel alloc]init];
            model.CorpAeraCode = @"";
            model.CorpName = @"";
            [self.corpArray insertObject:model atIndex:0];
            [self.corpPickerView reloadAllComponents];
        }else{
            [self.corpArray removeAllObjects];
            HXCorpListModel *model = [[HXCorpListModel alloc]init];
            model.CorpName = @"暂无企业";
            model.CorpAeraCode = @"";
            [self.corpArray insertObject:model atIndex:0];
            [self.corpPickerView reloadAllComponents];
        }
    } failure:^(NSError *err) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
}

- (IBAction)okBtnClick:(id)sender {
    NSMutableDictionary *mDict = [[NSMutableDictionary alloc]init];
    NSString *areaStr = [self.areaBtnSelectedView allCode];
    [mDict setObject:areaStr forKey:@"AeraCode"];
    NSString *corpKindStr = [self.corpKindBtnSelectedView allCode];
    [mDict setObject:corpKindStr forKey:@"CorpKind"];
    NSString *personKindStr = [self.personKindBtnSelectedView allCode];
    [mDict setObject:personKindStr forKey:@"PersonKind"];
    NSString *gradeStr = [self.gradeBtnSelectedView allCode];
    if (gradeStr.length == 0) {//没选资质等级
        [mDict setObject:@"" forKey:@"CorpOrg"];
    }else if(gradeStr.length != 0){
        NSString *corpdStr = [self.corpBtnSelectedView allCode];
        [mDict setObject:corpdStr forKey:@"CorpOrg"];
    }else{
        //NSAssert(0, @"判断是否选资质等级的时候 崩溃~~~~~~~~~~~~~");
    }
    [mDict setObject:@"" forKey:@"Query"];
    [self refreshData:mDict];
}

- (IBAction)siftBtnClick:(id)sender {
    if ([GlobalUtil isNilValue:self.siftTextField.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入正确企业名称"];
        return;
    }
    [self.view endEditing:YES];
    NSMutableDictionary *mDict= [[NSMutableDictionary alloc]init];
    [mDict setObject:self.siftTextField.text forKey:@"Query"];
    [self refreshData:mDict];
}

-(void)refreshData:(NSMutableDictionary *)mDict{
     [SVProgressHUD showWithStatus:@"正在获取人员" ];
    [NetworkAPI getPersonWithNum:@"0"
                            dict:mDict
                         success:^(HXPersonSelectedModel *result) {
                             [SVProgressHUD dismiss];
                             if ([result.code isEqualToString:@"200"]) {
                                 [self.view addSubview:self.maskView];
                                 [self.view addSubview:self.selectedPerson];
                                 self.personArray = result.corplist;
                                 self.selectedPerson.data = self.personArray;
                             }else{
                                 UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"获取失败" message:@"没有符合该条件的人员" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                                 [alert show];
                             }
                         } failure:^(NSError *err) {
                             [SVProgressHUD showErrorWithStatus:@"网络错误"];
                         }];
    
//    if ([result.code isEqualToString:@"200"]) {
//        self.index++;
//        [MBProgressHUD showSuccess:@"获取通知成功"];
//        [self.dataArray removeAllObjects];
//        [self.dataArray addObjectsFromArray:result.msglist];
//        [self.tableView reloadData];
//        if ([result.msglist count] < 10) {
//            [self.tableView.mj_header endRefreshing];
//            [self.tableView.mj_footer endRefreshingWithNoMoreData];
//            self.tableView.mj_footer.alpha = 1.0f;
//            return;
//        }
//    }else{
//        [MBProgressHUD showError:@"暂无消息数据"];
//        [self.tableView.mj_header endRefreshing];
//        [self.tableView.mj_footer endRefreshingWithNoMoreData];
//    }
//} failure:^(NSError *err) {
//    [self.tableView.mj_header endRefreshing];
//    //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//    [MBProgressHUD showError:@"网络错误"];
//    [self.tableView.mj_header endRefreshing];
//    [self.tableView.mj_footer endRefreshing];
}

-(void)loadMoreData{
    
}

#pragma mark - HXSelectedPersonResultViewDelegate
- (void)selectedPersonOkBtnClick {
    if ([self.delegate respondsToSelector:@selector(getPersonMsg:nameArray:)]) {
        [self.delegate getPersonMsg:self.selectedPerson.personIDArray nameArray:self.selectedPerson.personNameArray];
        [self.selectedPerson removeFromSuperview];
        [self.selectedPerson.personIDArray removeAllObjects];
        [self.selectedPerson.personNameArray removeAllObjects];
        [self.maskView removeFromSuperview];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

-(void)closeSideBar{
    [self.selectedPerson removeFromSuperview];
    [self.selectedPerson.personIDArray removeAllObjects];
    [self.selectedPerson.personNameArray removeAllObjects];
    [self.maskView removeFromSuperview];
}

#pragma mark - HXBtnSelectedViewDelegate
- (void)addMsgWithName:(NSString*)name{
    if ([name isEqualToString:AreaStr]) {
        [self.areaTextField becomeFirstResponder];
    }else if ([name isEqualToString:CorpKindStr]){
        [self.corpKindTextField becomeFirstResponder];
    }else if ([name isEqualToString:GradeStr]){
        [self.gradeTextField becomeFirstResponder];
    }else if ([name isEqualToString:CorpStr]){
        [self.corpTextField becomeFirstResponder];
    }else if ([name isEqualToString:PersonKindStr]){
        [self.personKindTextField becomeFirstResponder];
    }
}

//删除企业类型的时候刷新
-(void)reloadGradePerson{
    [self getGradeAndPersonData];
}


#pragma mark - UIPickerViewDelegate
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    if (pickerView.tag == AreaViewTag) {
        return 2;
    }else if (pickerView.tag == CorpKindViewTag){
        return 1;
    }else if (pickerView.tag == GradeViewTag){
        return 1;
    }else if (pickerView.tag == CorpViewTag){
        return 1;
    }else if (pickerView.tag == PersonViewTag){
        return 1;
    }else{
        return 0;
    }
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView.tag == AreaViewTag) {
        if (component == 0) {
            return self.areaArray.count;
        }else if (component == 1){
            NSInteger selectIndex = [self.areaPickerView selectedRowInComponent:0];
            HXAreaKindListModel *area = self.areaArray[selectIndex];
            return area.areas.count+1;
        }
    }else if (pickerView.tag == CorpKindViewTag){
       return self.corpKindArray.count;
    }else if (pickerView.tag == GradeViewTag){
        return self.gradeArray.count;
    }else if (pickerView.tag == CorpViewTag){
        return self.corpArray.count;
    }else if (pickerView.tag == PersonViewTag){
        return self.personKindArray.count;
    }else{
        return 0;
    }
    return 0;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView.tag == AreaViewTag) {
        if (component == 0) {
            HXAreaKindListModel *area = self.areaArray[row];
            return area.city;
        }else if (component == 1){
            if (row == 0) {
                return @"";
            }
            NSInteger selectIndex = [self.areaPickerView selectedRowInComponent:0];
            HXAreaKindListModel *area = self.areaArray[selectIndex];
            HXAreaKindAreasListModel *areas = area.areas[row-1];
            return areas.area;
        }
    }else if (pickerView.tag == CorpKindViewTag){
        HXCorpKindListModel *corp = self.corpKindArray[row];
        return corp.typeName;
    }else if (pickerView.tag == GradeViewTag){
        HXGradeKindListModel *grade = self.gradeArray[row];
        return grade.typeName;
    }else if (pickerView.tag == CorpViewTag){
        HXCorpListModel *corp = self.corpArray[row];
        return corp.CorpName;
    }else if (pickerView.tag == PersonViewTag){
        HXPersonKindListModel *grade = self.personKindArray[row];
        return grade.typeName;
    }
    return nil;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (pickerView.tag == AreaViewTag) {
        if (component == 0) {
            //刷新第一列
            [self.areaPickerView reloadComponent:1];
            //让第一列滚动到第0行
            [pickerView selectRow:0 inComponent:1 animated:YES];
        }else if (component == 1){
            NSInteger selectIndex = [self.areaPickerView selectedRowInComponent:0];
            HXAreaKindListModel *area = self.areaArray[selectIndex];
            if(row>0){
                HXAreaKindAreasListModel *areas = area.areas[row -1];
                self.areaTextField.text =  [NSString stringWithFormat:@"%@*%@",[NSString stringWithFormat:@"%@-%@",area.city,areas.area],areas.areacode];
            }else{
                self.areaTextField.text = @"";
            }

        }else{
           //NSAssert(0, @"添加人员选择地区崩溃~~~~~~~~~~~~~~~~");
        }
    }else if (pickerView.tag == CorpKindViewTag){
        HXCorpKindListModel *corp = self.corpKindArray[row];
        self.corpKindTextField.text = [NSString stringWithFormat:@"%@*%@",corp.typeName,corp.typeValue];
    }else if (pickerView.tag == GradeViewTag){
        HXGradeKindListModel *grade = self.gradeArray[row];
        self.gradeTextField.text = [NSString stringWithFormat:@"%@*%@",grade.typeName,grade.typeValue];
    }else if (pickerView.tag == CorpViewTag){
        HXCorpListModel *corp = self.corpArray[row];
        if ([GlobalUtil isNilValue:corp.CorpName]) {
            HXLog(@"%@",corp.CorpAeraCode);
        }
        HXLog(@"%@",corp.CorpAeraCode);
        self.corpTextField.text = [NSString stringWithFormat:@"%@*%@",corp.CorpName,corp.CorpOrg];
    }else if (pickerView.tag == PersonViewTag){
        HXPersonKindListModel *person = self.personKindArray[row];
        self.personKindTextField.text = [NSString stringWithFormat:@"%@*%@",person.typeName,person.typeValue];
    }
}

#pragma mark - TextFieldDelegate
-(void)textFieldDidEndEditing:(UITextField *)textField{
    HXLog(@"%@",textField.text);
    if ([GlobalUtil isNilValue:textField.text]) return;
    if ([textField.text isEqualToString:@"*"]) return;
    if (textField.text.length >10) {
        if ([[textField.text substringToIndex:(10)] isEqualToString:AlertOneStr]) return;
    }
    if (textField.text.length >8) {
        if ([[textField.text substringToIndex:(8)] isEqualToString:AlertTwoStr]) return;
    }
    if (textField.text.length >6) {
        if ([[textField.text substringToIndex:(6)] isEqualToString:AlertThreeStr]) return;
    }
    if (textField.text.length >4) {
       if ([[textField.text substringToIndex:(4)] isEqualToString:AlertFourStr]) return;
    }
    if (textField.text.length >6) {
        if ([[textField.text substringToIndex:(6)] isEqualToString:AlertFiveStr]) return;
    }

    if (textField.tag == AreaViewTag) {
        [self.areaBtnSelectedView giveMeMsg:textField.text];
        HXLog(@"%@",textField.text);
    }else if (textField.tag == CorpKindViewTag){
        [self.corpKindBtnSelectedView giveMeMsg:textField.text];
        [self getGradeAndPersonData];
        HXLog(@"%@",textField.text);
    }else if (textField.tag == GradeViewTag){
        [self.gradeBtnSelectedView giveMeMsg:textField.text];
        [self getCorpData];
        HXLog(@"%@",textField.text);
    }else if (textField.tag == CorpViewTag){
        [self.corpBtnSelectedView giveMeMsg:textField.text];
        HXLog(@"%@",textField.text);
    }else if (textField.tag == PersonViewTag){
        [self.personKindBtnSelectedView giveMeMsg:textField.text];
        HXLog(@"%@",textField.text);
    }
}

#pragma mark - 懒加载
//-(HXBtnSelectedView *)corpKindBtnSelectedView{
//    if (_corpKindBtnSelectedView == nil) {
//        _corpKindBtnSelectedView = [HXBtnSelectedView initWithName:@"企业类型"];
//        _corpKindBtnSelectedView.frame = CGRectMake(0, 0, 285, 40);
//        _corpKindBtnSelectedView.delegate = self;
//        [self.corpKindSelectedView addSubview:_corpKindBtnSelectedView];
//    }
//    return _corpKindBtnSelectedView;
//}

- (UITextField *)areaTextField{
    if (_areaTextField == nil) {
        _areaTextField = [[UITextField alloc]init];
        _areaTextField.tag = AreaViewTag;
        _areaTextField.delegate = self;
        _areaTextField.inputView = self.areaPickerView;
        [self.areaSelectedView addSubview:_areaTextField];
        _areaTextField.inputAccessoryView = self.keyboardDoneButtonBar;
    }
    return _areaTextField;
}

- (UITextField *)corpKindTextField{
    if (_corpKindTextField == nil) {
        _corpKindTextField = [[UITextField alloc]init];
        _corpKindTextField.tag = CorpKindViewTag;
        _corpKindTextField.delegate = self;
        _corpKindTextField.inputView = self.corpKindPickerView;
        [self.corpKindSelectedView addSubview:_corpKindTextField];
        _corpKindTextField.inputAccessoryView = self.keyboardDoneButtonBar;
    }
    return _corpKindTextField;
}

- (UITextField *)gradeTextField{
    if (_gradeTextField == nil) {
        _gradeTextField = [[UITextField alloc]init];
        _gradeTextField.tag = GradeViewTag;
        _gradeTextField.delegate = self;
        _gradeTextField.inputView = self.gradePickerView;
        [self.gradeSelectedView addSubview:_gradeTextField];
        _gradeTextField.inputAccessoryView = self.keyboardDoneButtonBar;
    }
    return _gradeTextField;
}

- (UITextField *)corpTextField{
    if (_corpTextField == nil) {
        _corpTextField = [[UITextField alloc]init];
        _corpTextField.tag = CorpViewTag;
        _corpTextField.delegate = self;
        _corpTextField.inputView = self.corpPickerView;
        [self.corpSelectedView addSubview:_corpTextField];
        _corpTextField.inputAccessoryView = self.keyboardDoneButtonBar;
    }
    return _corpTextField;
}

- (UITextField *)personKindTextField{
    if (_personKindTextField == nil) {
        _personKindTextField = [[UITextField alloc]init];
        _personKindTextField.tag = PersonViewTag;
        _personKindTextField.delegate = self;
        _personKindTextField.inputView = self.personKindPickerView;
        [self.personKindSelectedView addSubview:_personKindTextField];
        _personKindTextField.inputAccessoryView = self.keyboardDoneButtonBar;
    }
    return _personKindTextField;
}

- (UIPickerView *)areaPickerView{
    if (_areaPickerView == nil) {
        _areaPickerView = [[UIPickerView alloc]init];
        _areaPickerView.dataSource = self;
        _areaPickerView.delegate = self;
        _areaPickerView.tag = AreaViewTag;
    }
    return _areaPickerView;
}

- (UIPickerView *)corpKindPickerView{
    if (_corpKindPickerView == nil) {
        _corpKindPickerView = [[UIPickerView alloc]init];
        _corpKindPickerView.dataSource = self;
        _corpKindPickerView.delegate = self;
        _corpKindPickerView.tag = CorpKindViewTag;
    }
    return _corpKindPickerView;
}

-(UIPickerView *)gradePickerView{
    if (_gradePickerView == nil) {
        _gradePickerView = [[UIPickerView alloc]init];
        _gradePickerView.dataSource = self;
        _gradePickerView.delegate = self;
        _gradePickerView.tag = GradeViewTag;
    }
    return _gradePickerView;
}

-(UIPickerView *)corpPickerView{
    if (_corpPickerView == nil) {
        _corpPickerView = [[UIPickerView alloc]init];
        _corpPickerView.dataSource = self;
        _corpPickerView.delegate = self;
        _corpPickerView.tag = CorpViewTag;
    }
    return _corpPickerView;
}

-(UIPickerView *)personKindPickerView{
    if (_personKindPickerView == nil) {
        _personKindPickerView = [[UIPickerView alloc]init];
        _personKindPickerView.dataSource = self;
        _personKindPickerView.delegate = self;
        _personKindPickerView.tag = PersonViewTag;
    }
    return _personKindPickerView;
}

- (UITapGestureRecognizer *)tapGestureRec{
    if (_tapGestureRec == nil) {
        _tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeSideBar)];
        _tapGestureRec.delegate=self;
    }
    return _tapGestureRec;
}

- (UIView *)maskView{
    
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _maskView.backgroundColor = [UIColor blackColor];
        _maskView.userInteractionEnabled = YES;
        [_maskView addGestureRecognizer:self.tapGestureRec];
    }
    return _maskView;
}

- (HXSelectedPersonResultView *)selectedPerson{
    if (_selectedPerson == nil) {
        _selectedPerson = [HXSelectedPersonResultView viewWithXIB:self];//280*433
        _selectedPerson.layer.cornerRadius = 7;
        _selectedPerson.delegate = self;
//        [self.view addSubview:self.maskView];
        _selectedPerson.x = (HXSCREEN_WIDTH - 280)*0.5;
        _selectedPerson.y = 80;
//        [self.view addSubview:_selectedPerson];
    }
    return _selectedPerson;
}



- (NSMutableArray<HXGradeKindListModel *> *)gradeArray{
    if (_gradeArray == nil) {
        _gradeArray = [[NSMutableArray alloc]init];
        HXGradeKindListModel *model = [[HXGradeKindListModel alloc]init];
        model.typeName = @"请先选择企业类型";
        model.typeValue = @"";
        [_gradeArray insertObject:model atIndex:0];
    }
    return _gradeArray;
}

-(NSMutableArray<HXPersonKindListModel *> *)personKindArray{
    if (_personKindArray == nil) {
        _personKindArray = [[NSMutableArray alloc]init];
        HXPersonKindListModel *model = [[HXPersonKindListModel alloc]init];
        model.typeName = @"请先选择企业类型";
        model.typeValue = @"";
        [self.personKindArray insertObject:model atIndex:0];}
    return _personKindArray;
}

-(NSMutableArray<HXCorpListModel *> *)corpArray{
    if (_corpArray == nil) {
        _corpArray = [[NSMutableArray alloc]init];
        HXCorpListModel *model = [[HXCorpListModel alloc]init];
        model.CorpName = @"请先选择其他筛选信息";
        model.CorpAeraCode = @"";
        [self.corpArray insertObject:model atIndex:0];
    }
    return _corpArray;
}

- (NSMutableArray<HXCorpKindListModel *> *)corpKindArray{
    if (_corpKindArray == nil) {
        _corpKindArray = [[NSMutableArray alloc]init];
    }
    return _corpKindArray;
}

- (NSMutableArray<HXAreaKindListModel *> *)areaArray{
    if (_areaArray == nil) {
        _areaArray = [[NSMutableArray alloc]init];
    }
    return _areaArray;

}


-(UIToolbar*)keyboardDoneButtonBar{
    if(!_keyboardDoneButtonBar){
        _keyboardDoneButtonBar= [[UIToolbar alloc] init];
        _keyboardDoneButtonBar.barStyle = UIBarStyleDefault;
        _keyboardDoneButtonBar.tintColor = nil;
        [_keyboardDoneButtonBar sizeToFit];
        UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                                  target:nil
                                                                                  action:nil];
        UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancelBtn addTarget:self action:@selector(CancelClicked:) forControlEvents:UIControlEventTouchUpInside];
        cancelBtn.size = CGSizeMake(44, 44);
        [cancelBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithCustomView:cancelBtn];
        
        UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [okBtn addTarget:self action:@selector(DoneClicked:) forControlEvents:UIControlEventTouchUpInside];
        okBtn.size = CGSizeMake(44, 44);
        [okBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [okBtn setTitle:@"确定" forState:UIControlStateNormal];
        okBtn.titleLabel.textColor = [UIColor blueColor];
        UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
        [_keyboardDoneButtonBar setItems:[NSArray arrayWithObjects:cancelButton,flexItem,doneButton, nil]];
        
    }
    return _keyboardDoneButtonBar;
}
-(void)CancelClicked:(UIButton *)btn{
    self.areaTextField.text = @"";
    self.corpKindTextField.text = @"";
    self.corpTextField.text = @"";
    self.gradeTextField.text = @"";
    self.personKindTextField.text = @"";
    [self.view endEditing:YES];
}

-(void)DoneClicked:(UIButton *)btn{

    [self.view endEditing:YES];
}


@end
